package chw412;
import java.util.*;
import pacworld.VisiblePackage;
import pacworld.*;

public class KnownPackage implements Comparable<KnownPackage>, Comparator<KnownPackage> {

   private int id = 0;
   private int x = 0;
   private int y = 0;
   private int destX = 0;
   private int destY = 0;
   public boolean held = false;
   public boolean ordered = false;

   public KnownPackage(int id, int x, int y, int destX, int destY, boolean held, boolean ordered) {
	   this.id = id;
	   this.x = x;
	   this.y = y;
	   this.destX = destX;
	   this.destY = destY;
	   this.held = held;
	   this.ordered = ordered;
   }

   public KnownPackage(VisiblePackage vp) {
	   this.id = vp.getId();
	   this.x = vp.getX();
	   this.y = vp.getY();
	   this.destX = vp.getDestX();
	   this.destY = vp.getDestY();
	   this.held = vp.isHeld();
	   this.ordered = false;
   }
   
   /** Get the X coordinate of the location to deliver the package. */
   public int getDestX() {
      return destX;
   }

   /** Get the Y coordinate of the location to deliver the package. */
   public int getDestY() {
      return destY;
   }
   
   /** Get the unique integer id for the package. */
   public int getId() {
      return id;
   }

   /** Get the X location of the package. */
   public int getX() {
      return x;
   }

   /** Get the Y location of the package. */
   public int getY() {
      return y;
   }

   public void update_loc(Location new_loc){
	   this.x = new_loc.getX();
	   this.y = new_loc.getY();
   }
   
   /** Tests if this object is equivalent to another object by comparing the id's of the packages. */
   public boolean equals(Object obj) {

      KnownPackage otherPac;

      if (obj instanceof KnownPackage) {
         otherPac = (KnownPackage)obj;
         if (id == otherPac.getId())
            return true;
      }
      return false;
   }

   public String toString() {
      return "Package " + id + ": Loc=(" + x + ", " + y + "), " +
      "Dest=(" + destX + ", " + destY + "), Held=" + held + "Ordered=" + ordered;
   }

	@Override
	public int compare(KnownPackage o1, KnownPackage o2) {
		// TODO Auto-generated method stub
		return o1.getId() - ((KnownPackage)o2).getId();
	}

	@Override
	public int compareTo(KnownPackage o) {
		   if(this.id < ((KnownPackage)o).getId())
			   return -1;
		   else if(this.id == ((KnownPackage)o).getId())
			   return 0;
		   else
			   return 1;
	}
}
